<?php

namespace App\Http\Resources\Kms\Attendance;

use App\Http\Resources\BaseResource;
use App\Models\Kms\Attendance\AttendanceDailyGatherModel;
use Illuminate\Http\Request;

class FieldListResource extends BaseResource
{
    /**
     * @param Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            "id"             => $this->id,
            "date"           => $this->date,
            "name"           => $this->userRel->name,
            "nickname"       => $this->userRel->nickname,
            "userId"         => $this->userId,
            "normalDuration" => $this->normalDuration,
            "missDuration"   => $this->missDuration,
            "traceDistance"  => $this->traceDistance,
            "status"         => $this->status,
            "statusText"     => translateEnumCodeToCn(AttendanceDailyGatherModel::STATUS_TEXT, $this->status),
            "deviceCount"    => $request->withCount->where("dailyGatherId", $this->id)->count()
        ]; // TODO: Change the autogenerated stub
    }
}
